<%--
  Created by IntelliJ IDEA.
  User: 20064
  Date: 2020/2/12
  Time: 16:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>用户登录</title>
    <!-- 字体 -->
    <link href="https://fonts.font.im/css?family=Ruslan+Display" rel="stylesheet">

    <!-- 图标 -->
    <link rel="icon" type="image/png" sizes="144x144" href="../images/airplane.png"/>
    <link rel="apple-touch-icon" type="image/png" sizes="144x144" href="../images/airplane.png"/>
    <link href="../js/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">

    <!-- 其他 -->
    <link rel="stylesheet" href="../js/bootstrap-4.4.1-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/userStyle.css">


</head>
<body>
<div class="container">
    <div class="row">&nbsp;</div>
    <div class="row">
        <div class="header">
            <p>世界那么大，我想去看看。</p>
            <p>There is such a lot of things on the world to see.</p>
        </div>
    </div>
    <div class="row">&nbsp;</div>
    <div class="row my-row">
        <div class="myForm rounded m-auto rounded shadow-lg">
            <form action="userLogin.do" method="post">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text"><i class="fa fa-user fa-fw"></i></span>
                    </div>
                    <input type="text" class="form-control" placeholder="请输入账号" required="required" name="userAccount">
                </div>
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text"><i class="fa fa-key fa-fw"></i></span>
                    </div>
                    <input type="password" class="form-control" placeholder="请输入密码" required="required" name="userPwd">
                </div>
                <div class="fn text-right">
                    <a href="./register.jsp" class="fn-register">没有账号？</a>
                    <a href="./forgetPwd.jsp" class="fn-forget">忘记密码？</a>
                </div>
                <div class="my-button">
                    <button class="btn btn-success" type="submit">登录</button>
                </div>
            </form>
        </div>
    </div>
</div>
<c:if test="${msg!=null}">
    <script type="text/javascript">
        alert("${msg}");
    </script>
</c:if>



</body>

<script type="text/javascript" src="../js/jquery-3.4.1/jquery-3.4.1.js"></script>
<script type="text/javascript" src="../js/bootstrap-4.4.1-dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
    // function login(btn) {
    //     $(btn).text("登陆中。。。");
    //     var confirmUser = checkUserInfo();
    //     if (confirmUser === true) {
    //         $("form").submit();
    //     } else {
    //         $("input[name='userAccount']").val("");
    //         $("input[name='userPwd']").val("");
    //         $(btn).text("登陆");
    //     }
    // }

    $("form").submit(function () {
        $("button").text("登陆中。。。");
        var confirmUser = checkUserInfo();
        if (confirmUser === true) {
            return true;
        } else {
            $("input[name='userAccount']").val("");
            $("input[name='userPwd']").val("");
            $(".btn").text("登陆");
        }
        return false;
    });

    function checkUserInfo() {
        var check = false;
        $.ajax({
            async: false,
            url: "checkUserInfo.do",
            type: "post",
            data: {userAccount: $("input[name='userAccount']").val(), userPwd: $("input[name='userPwd']").val()},
            dataType: "json",
            success: function (result) {
                check = result.check;
                if (check === false) {
                    alert(result.msg);
                }
            }
        });
        return check;
    }


</script>

</html>
